Hugi Magazine #33: MP3 Power

Hugi #33 header graphic

Dark Basic Pro Programming #03 (By Fable Fox)

BASIC Basics

Cool, huh? Well, now let's get back to earth. Well, print is a command that prints a string. And it is followed by a string. The same rule applies to loading music and playing music. They're all commands and followed by an extra parameter. Some, like "wait key", don't need one.

We can add a comment to our source code for informational purpose. There are two types of comments, line and block. Just look at the source code with comments below. Comments are not processed. So you can write anything you want.

remstart
this is the beginning of a multiline comment, which
can be refered to as a block of comment. You can
add as many comments as you want, just remember to
close it with the keyword below
remend

rem this is a single line comment

print "HUGI rulez!" rem a comment can be add here too!
load music "data\canon.mid",1
play music 1
wait key

Now that I have taught you about comments, let's go to another important aspect of BASIC programming, variables. Variables are words that you use to hold data or information. A variable actually points to a memory location that hold the data, but you need need understand that now. Just look at the source code below.

name$ = "fable fox"
print name$
wait key

name$ is a variable of type string. It holds the string "fable fox". There are many other types of variables like integer, real, byte, Boolean, dword, double integer and double float. In DBP, you can use uppercase letter or lowercase letter and it has no difference. NAME$ and name$ refer to the same variables. To use real, you must use the symbol '#', but you don't have to use anything for integer.

name$ = "fable fox"
razor = 1911
fable# = 31.337
print name$
print razor
print fable#
wait key

Run it and you will get this:

fable fox
1911
31.337 

If you receive a different number for fable#, such as 31.337005867, it is because of how floats are stored, and you are using the demo at version 1.058. If you have the full version, upgrade to version 1.066 and you will not face this problem. There are other data types like array which we're going to learn one day, but this is enough for now.

Fable Fox